home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / NextAnswers / 1439_protected_or_private_instance_variables.rtf < prev    next >
Text File  |  1993-11-08  |  2KB  |  82 lines

  1. {\rtf0\ansi{\fonttbl\f0\fnil Times-Roman;\f1\fmodern Courier;\f3\fmodern Ohlfs;}
  2. \paperw11440
  3. \paperh9000
  4. \margl120
  5. \margr120
  6. {\colortbl;\red0\green0\blue0;}
  7. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\f0\b0\i0\ulnone\fs28\fc1\cf1 Q:  How can I get at the 
  8. \b protected
  9. \b0  or 
  10. \b private
  11. \b0  instance variables of a class?\
  12.  
  13. \i     \
  14.  
  15. \i0 A:  There is a construct which allows you to access all of the instance variables of an object as if it were a C-structure.  We don't encourage it (although it is documented in the Objective-C chapter of the Concepts manual).  But if you really really must, then you can use the @defs construct.  @defs allows you to essentially import all the instance variables of a given class into a structure local to your application.\
  16. \
  17.  
  18. \f1\fs24     struct    InternalDetails\
  19.     \{\
  20.     @defs(Matrix);\
  21.     \};\
  22.     \
  23.     struct InternalDetails  *matrixGoodies;\
  24.     \
  25.     matrixGoodies = (struct InternalDetails *)[Matrix new];\
  26.     if (matrixGoodies->mFlags.radioMode == ...)\
  27.  
  28. \f0\fs28 \
  29.  
  30. \b Important Note:
  31. \b0   Never use this technique to set or look at the values of instance variables whose names start with an underline in the Application Kit.  The contents of those variables are for internal use and subject to change with releases.  It's OK to use  \
  32. \
  33.     
  34. \f1\fs24 @defs
  35. \f0\fs28    or   
  36. \f1\fs24 Matrix *m
  37. \f0\fs28 ; \
  38. \
  39. type constructs to get at the 
  40. \b private 
  41. \b0 or
  42. \b  protected
  43. \b0  variables which don't begin with an underline.  However you should only do this as a last resort.\
  44. \
  45.  
  46. \i TERMINOLOGY NOTE:  Prior to the Release 3, there were only 
  47. \b public
  48. \b0  and 
  49. \b private
  50. \b0  instance variables.  By default, all instance variables were 
  51. \b private
  52. \b0  unless specified as 
  53. \b public
  54. \b0 .  Release 3 introduced the concept of 
  55. \b protected
  56. \b0  instance variables.  
  57. \b Protected
  58. \b0  instance variables are available to a class and its subclasses.  
  59. \b Private
  60. \b0  instance variables are available to that class only—not to the subclasses.  What was a 
  61. \b private
  62. \b0  instance variable under Release 2 is a 
  63. \b protected
  64. \b0  variable under Release 3.  By default all instance variables under Release 3 are 
  65. \b protected
  66. \b0 . \
  67. \
  68. See the Release 3 Compiler release notes for further information on 
  69. \b private/protected/public
  70. \b0  instance variables.  \
  71.  
  72. \i0 \
  73. QA605                \
  74.  
  75. \gray333 \
  76.  
  77. \gray0 Valid for 1.0, 2.0, 3.0\
  78.  
  79. \gray333 \
  80.  
  81.  
  82.